# Contributor: jane400 <alpine@j4ne.de>
# Maintainer: fossdd <fossdd@pwned.life>
pkgname=cinny
pkgver=4.2.2
_releasedate="2024-10-16"
pkgrel=0
pkgdesc="Yet another matrix client"
url="https://cinny.in"
# limited by tauri platform support
# and by nodejs module rollup
arch="x86_64 aarch64"
license="AGPL-3.0-only"
depends="gst-plugins-good"
makedepends="
	cargo
	gtk+3.0-dev
	libayatana-appindicator-dev
	nodejs
	npm
	openssl-dev
	tauri-cli
	vips-dev
	webkit2gtk-dev
	"
# Adapted from https://github.com/flathub/in.cinny.Cinny
source="
	cinny-$pkgver.zip::https://github.com/cinnyapp/cinny-desktop/releases/download/v$pkgver/cinny-desktop-v$pkgver.zip
	0001-disable-tauri-updater.patch
	in.cinny.Cinny.appdata.xml.in
	cinny.desktop
"
builddir="$srcdir/cinny-desktop"
_jsdir="$builddir/cinny"
_rustdir="$builddir/src-tauri"
options="net !check" # no checks

# secfixes:
#   2.2.4-r1:
#     - CVE-2023-28103

export CARGO_PROFILE_RELEASE_OPT_LEVEL=2
export NODE_OPTIONS="--max-old-space-size=4000"

prepare() {
	default_prepare

	cp "$builddir/config.json" $_jsdir/
	# they don't know how to specify dependencies correctly
	cd "$_jsdir"
	npm ci --legacy-peer-deps

	cd "$builddir"
	npm ci

	cd "$_rustdir"
	cargo fetch --target="$CTARGET" --locked
}

build() {
	cargo-tauri build -b "none"
}

package() {
	install -Dm755 -t "$pkgdir"/usr/bin "$_rustdir"/target/release/cinny

	install -Dm644 -t "$pkgdir"/usr/share/applications/ "$srcdir"/cinny.desktop

	# Generate appdata file
	mkdir -p "$pkgdir"/usr/share/metainfo/
	export DATE="$_releasedate"
	export VERSION="$pkgver-$pkgrel"
	envsubst < "$srcdir"/in.cinny.Cinny.appdata.xml.in > "$pkgdir"/usr/share/metainfo/in.cinny.Cinny.appdata.xml

	install -Dm644 "$_rustdir"/icons/32x32.png "$pkgdir"/usr/share/icons/hicolor/32x32/apps/cinny.png
	install -Dm644 "$_rustdir"/icons/128x128.png "$pkgdir"/usr/share/icons/hicolor/128x128/apps/cinny.png
	install -Dm644 "$_rustdir"/icons/128x128@2x.png	"$pkgdir"/usr/share/icons/hicolor/256x256/apps/cinny.png
	install -Dm644 "$_rustdir"/icons/icon.png "$pkgdir"/usr/share/icons/hicolor/512x512/apps/cinny.png
}

sha512sums="
ea9d8d3a8cb88463420b757e7a44c19cae4c5573009260de6bfbcf80f57b40c6e0ab488b9281f983f314d5945d47842ca5d1a674794eaeb62a5862d3208c284c  cinny-4.2.2.zip
0884a48c4a74c13b1fc3ce4a25fa9d44766f0e7ee6f6ec75c287a145e8df9c318684aa3defb2a6e2ab348d164ebb6d8e86d79a6ba97fb3519af49ee476ff9127  0001-disable-tauri-updater.patch
f5cdcf87cbb78764323ca2dffc1f5a76c8db28f3683cc6e8b8f444fe73638963a1df882f2ec937c470047864aa6398fc1ccf47275ea5f8e11d10560c5f553ade  in.cinny.Cinny.appdata.xml.in
f94ce9099642c1b765399d2d3c617c2cdb63fef6fffa9e5556d8eba7a26090ce429ded5b2a5280d79f9986ab6ad86a6cfdfd27c39dbb06418fc57b22cef313c1  cinny.desktop
"
